
var json  = [{
    id:0,
    equip:'026320',
    name:'装甲步兵战车',
    equip_classify:'装甲车',
    state:'正常',
    price:'18000',
    modalities:'自购',
    car_classify:'装甲车辆A',
    userD: '北京护卫队',
    deposit :'北京',
    responsiblePerson: '小王',
    illustrate :'装备杀伤力一般'

},{
    id:1,
    equip:'026230',
    name:'装甲步兵战车',
    equip_classify:'装甲车',
    state:'正常',
    price:'18000',
    modalities:'自购',
    car_classify:'装甲车辆A'
},{
    id:2,
    equip:'126320',
    name:'装甲步兵战车',
    equip_classify:'装甲车',
    state:'维修中',
    price:'18000',
    modalities:'分配',
    car_classify:'装甲车辆B'
},{
    id:3,
    equip:'226320',
    name:'重型坦克',
    equip_classify:'装甲车',
    state:'正常',
    price:'18000',
    modalities:'自购',
    car_classify:'装甲车辆A'
},{
    id:4,
    equip:'226320',
    name:'装甲步兵战车',
    equip_classify:'装甲车',
    state:'正常',
    price:'18000',
    modalities:'自购',
    car_classify:'装甲车辆A'
},{
    id:5,
    equip:'131320',
    name:'装甲步兵战车',
    equip_classify:'装甲车',
    state:'正常',
    price:'18000',
    modalities:'自购',
    car_classify:'装甲车辆A'
},{
    id:6,
    equip:'123120',
    name:'轻型坦克',
    equip_classify:'装甲车',
    state:'正常',
    price:'18000',
    modalities:'自购',
    car_classify:'装甲车辆A'
},
{
    id:7,
    equip:'121230',
    name:'装甲步兵战车',
    equip_classify:'装甲车',
    state:'正常',
    price:'18000',
    modalities:'自购',
    car_classify:'装甲车辆B'
},{
    id:8,
    equip:'763120',
    name:'水陆两栖战车',
    equip_classify:'装甲车',
    state:'正常',
    price:'18000',
    modalities:'自购',
    car_classify:'装甲车辆A'
},
{
    id:9,
    equip:'123031',
    name:'水陆两栖战车',
    equip_classify:'装甲车',
    state:'正常',
    price:'18000',
    modalities:'自购',
    car_classify:'装甲车辆B'
},]

var oTable = document.querySelector('.xuan-ran');
var oUl = document.querySelector('#pagin');
var fen_last = document.querySelector('#fen_last');
var ranArr;
var chaarr=[];
var cha=true;
var xiuG;
var xiuGNum ;
//按钮下拉；
var dian = document.querySelectorAll('.nav ul li');
for(var i=0;i<dian.length;i++){
    dian[i].onclick = function(){
        console.log(123)
      console.log(this.lastElementChild.style.height)  ;
      if(this.lastElementChild.style.height=='0px'){
        this.lastElementChild.style.height ='auto';
      }else{
        this.lastElementChild.style.height ='0px';

      }
    }
}
//获取添加数据
function addData(){
    var addJson={
     equip: localStorage.getItem('lang0'),
    name:localStorage.getItem('lang1'),
     equip_classify:localStorage.getItem('xiala'),
     state: localStorage.getItem('zt'),
     price:localStorage.getItem('lang2'),
     modalities:localStorage.getItem('xiala1'),
     car_classify:'装甲车辆C',
     userD: localStorage.getItem('lang3'),
     deposit :localStorage.getItem('lang4'),
     responsiblePerson: localStorage.getItem('lang5'),
     illustrate :localStorage.getItem('lang6')
}
return addJson;

}
//点击修改
oTable.addEventListener('click',look);
function look(){
    if(event.target.innerHTML=='修改'){
      
        xiuG = true;
        xiuGNum = event.target.parentNode.parentNode.parentNode.firstElementChild.firstElementChild.name
     localStorage.setItem('onling',xiuGNum);
        window.location.replace("../pages/xiuEquip.html");
    }
}
console.log(xiuGNum);
function xiuData(){
    var addJson={
        equip: localStorage.getItem('xiu0'),
       name:localStorage.getItem('xiu1'),
        equip_classify:localStorage.getItem('xl'),
        state: localStorage.getItem('zt1'),
        price:localStorage.getItem('xiu2'),
        modalities:localStorage.getItem('xl1'),
        car_classify:'装甲车辆C',
        userD: localStorage.getItem('xiu3'),
        deposit :localStorage.getItem('xiu4'),
        responsiblePerson: localStorage.getItem('xiu5'),
        illustrate :localStorage.getItem('xiu6')
   }
   return addJson;
}

console.log(json);
path =0;
yeNum = 4;

//渲染页面
randding();
function randding(){
    oTable.innerHTML=`<tr>
    <td>全选</td>
    <td>装备编号</td>
    <td>装备名称</td>
    <td>装备分类</td>
    <td>装备状态</td>
    <td>价格</td>
    <td>筹组方式</td>
    <td>操作</td>
 </tr>`
 if(localStorage.getItem('lang0')!=null){
    var aD =  addData();
    json.push(aD);
 };
 console.log(xiuG);
 if(localStorage.getItem('xiu0')!=null){
    for(var i=0;i<json.length;i++){
     console.log(json[i].equip==xiuGNum,json[i].equip,xiuGNum)
        if(json[i].equip==localStorage.getItem('onling')){
          json[i].equip=localStorage.getItem('xiu0'),
          json[i]. name=localStorage.getItem('xiu1'),
          json[i].  equip_classify=localStorage.getItem('xl'),
          json[i].  state= localStorage.getItem('zt1'),
          json[i]. price=localStorage.getItem('xiu2'),
          json[i]. modalities=localStorage.getItem('xl1'),
        json[i].  car_classify='装甲车辆C',
        json[i]. userD= localStorage.getItem('xiu3'),
        json[i]. deposit =localStorage.getItem('xiu4'),
        json[i]. responsiblePerson= localStorage.getItem('xiu5'),
        json[i]. illustrate =localStorage.getItem('xiu6')
        }
    }
 }
    ranArr = [];
    var ye=null;
    if(cha){
        ranArr =json.slice(path*yeNum, yeNum*(path+1))
        ye=json;
    }else{
        ranArr = chaarr.slice(path*yeNum, yeNum*(path+1));
        console.log(123);
        cha = true;
        ye=chaarr;
    }
    localStorage.clear();
    
    

for(var i=0;i<ranArr.length;i++){
    var oTr = document.createElement('tr');
    oTr.innerHTML=`
    <td><input type="checkbox" name="${ranArr[i].equip}" id="" index ="${ranArr[i].equip}"></td>
    <td>${ranArr[i].equip}</td>
    <td>${ranArr[i].name}</td>
    <td>${ranArr[i].equip_classify}</td>
    <td>${ranArr[i].state}</td>
    <td>${ranArr[i].price}</td>
    <td>${ranArr[i].modalities}</td>
    <td>
    <div><span class="btn btn-primary edit">查看</span>
    <span class="btn btn-danger del">修改</span>
    <span class="btn btn-primary edit">删除</span></div></td>
</tr>`;
    oTable.appendChild(oTr);
    }
    //计算页数渲染

        var calculation = Math.floor((ye.length)/yeNum+1);
        console.log(Math.floor((ye.length)/yeNum)+1);
        oUl.innerHTML = `
        <li>
        <a href="#" aria-label="Previous">
          <span aria-hidden="true">&laquo;</span>
        </a>
      </li>
      
      <li id="fen_last">
        <a href="#" aria-label="Next" >
          <span aria-hidden="true">&raquo;</span>
        </a>
      </li>
        `
        for(var j=0;j<calculation;j++){   
            var oLi = document.createElement('li');     
            oLi.innerHTML=`<a>${j+1}</a>`;   
            oUl.insertBefore(oLi,oUl.lastElementChild);
          
            // console.log(oUl,oLi,oUl.lastElementChild);
        }
    }
    

//删除
oTable.addEventListener('click',detlet);
function detlet(){
    if(event.target.innerHTML=='删除'){
      oTable.removeChild(event.target.parentNode.parentNode.parentNode);
      var strName = event.target.parentNode.parentNode.parentNode.firstElementChild.firstElementChild.name;
      for(var i=0;i<json.length;i++){
       if(json[i].equip ==strName){
          
           json.splice(i,1);
           console.log(json.length);
       } 
      }  
    randding();
    }
}
//查询
var oInquire = document.querySelector('.inquire');
oInquire.addEventListener('click',inquireFn);
function inquireFn(){
    chaarr = [];
    var iXin = document.querySelector('.inquire-xinxi');
    for(var i=0;i<json.length;i++){
        if(json[i].name.includes(iXin.value)||json[i].equip.includes(iXin.value)){
            //显示筛选出来的
            chaarr.push(json[i]);
            cha =false;
            console.log(cha);
        }
    }
    randding();
}

//点击换页
oUl.addEventListener('click',transFn);
function transFn(){
    path = event.target.innerText-1;
    ranArr = [];
    randding();
}







